﻿@using Smartstore.Core.Identity
@using Smartstore.Web.Models.Identity

@model LoginModel

@{
    Assets.AppendTitleParts(T("PageTitle.Login"));
    Assets.AddMetaRobots();

    var registerUrl = Url.RouteUrl("Register");
    var returnUrl = Context.Request.Query["returnUrl"].ToString();
    if (returnUrl.HasValue())
    {
        registerUrl = Display.ModifyQueryString(registerUrl, "returnUrl=" + returnUrl.UrlEncode(), null);
    }

    var currentUser = WorkContext.CurrentCustomer;
}

<div class="page login-page">
	<div class="page-title">
		<h1>@T("Account.Login.Welcome")</h1>
	</div>

	<div class="row mt-4">
		<div class="col-12 col-md-7 col-lg-6 col-xl-5 order-md-last">
			<div class="card shadow-sm p-4 mb-5 mb-md-0 login-box">
				<h3 class="h4 mb-0">
					@T("Account.Login.ReturningCustomer")
				</h3>
				<hr />

                <div asp-validation-summary="ModelOnly">@T("Account.Login.Unsuccessful")</div>

				<!-- SignIn Form -->
                <form asp-route="Login" asp-route-returnurl="@returnUrl" method="post" autocomplete="off">
                    <input asp-for="CustomerLoginType" type="hidden" />
                    @if (Model.CustomerLoginType == CustomerLoginType.Username)
                    {
                        <div class="form-group">
                            <div class="input-group input-group-lg has-icon">
                                <input asp-for="Username" class="username" autofocus="autofocus" />
                                <span class="input-group-icon text-muted">
                                    <i class="icm icm-user"></i>
                                </span>
                            </div>
                            <span asp-validation-for="Username"></span>
                        </div>
                    }
                    else if (Model.CustomerLoginType == CustomerLoginType.Email)
                    {
                        <div class="form-group">
                            <div class="input-group input-group-lg has-icon">
                                <input asp-for="Email" class="email" autofocus="autofocus" />
                                <span class="input-group-icon text-muted">
                                    <i class="icm icm-envelope-open"></i>
                                </span>
                            </div>
                            <span asp-validation-for="Email"></span>
                        </div>
                    }
                    else
                    {
                        <div class="form-group">
                            <div class="input-group input-group-lg has-icon">
                                <input asp-for="UsernameOrEmail" class="username" autofocus="autofocus" />
                                <span class="input-group-icon text-muted">
                                    <i class="icm icm-user"></i>
                                </span>
                            </div>
                            <span asp-validation-for="UsernameOrEmail"></span>
                        </div>
                    }

                    <div class="form-group">
                        <div class="input-group input-group-lg has-icon">
                            <input asp-for="Password" class="password" autocomplete="off" />
                            <span class="input-group-icon text-muted">
                                <i class="icm icm-shield"></i>
                            </span>
                        </div>
                        <span asp-validation-for="Password"></span>
                    </div>

                    <div class="form-group d-flex justify-content-between">
                        <input asp-for="RememberMe" sm-switch="false" />
                        <div class="forgot-password">
                            <a asp-route="PasswordRecovery">@T("Account.Login.ForgotPassword")</a>
                        </div>
                    </div>

                    <captcha sm-enabled="Model.DisplayCaptcha" class="form-group" />

                    <div class="form-group">
                        <button type="submit" class="btn btn-primary btn-lg btn-block btn-login">
                            @T("Account.Login.LoginButton")
                        </button>
                    </div>

                    <div sm-suppress-if-empty-zone="external_auth_buttons" class="form-group external-auth-buttons mb-0">
                        <div class="text-center text-uppercase mb-2">
                            - @T("Common.Or") -
                        </div>
                        <div class="row flex-wrap justify-content-center xs-gutters">
                            <zone name="external_auth_buttons" />
                        </div>
                    </div>

                    <zone name="after_login_buttons" />
                </form>
			</div>
		</div>
		<div class="col-12 col-md-5 col-lg-6 col-xl-7 order-md-first">
			<div class="page-info">
				@await Component.InvokeAsync("TopicBlock", new { systemName = "LoginRegistrationInfo", bodyOnly = true, isLead = true })
			</div>

			<div class="register-block">
				@if (Model.CheckoutAsGuest)
				{
                    @await Component.InvokeAsync("TopicBlock", new { systemName = "CheckoutAsGuestOrRegister", bodyOnly = true })
					<div class="row sm-gutters">
						<div class="col-sm-6 col-md-12 col-lg-6 pb-2 pb-lg-0">
							<a class="btn btn-warning btn-lg btn-block register-button" href="@registerUrl">
								@T("Account.Register.Button")
							</a>
						</div>
						<div class="col-sm-6 col-md-12 col-lg-6">
							<a class="btn btn-secondary btn-lg btn-block checkout-as-guest-button" asp-route="Checkout">
								<span>@T("Account.Login.CheckoutAsGuest")</span>
								<i class="fa fa-angle-right"></i>
							</a>
						</div>
					</div>
				}
				else
				{
					<div class="row">
						<div class="col-12 col-lg-auto">
							<a class="btn btn-warning btn-lg btn-block register-button" href="@registerUrl">
								@T("Account.Register.Button")
							</a>
						</div>
					</div>
				}
			</div>
		</div>
	</div>
</div>
